// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-destructuring-assignment
es6id: 12.14.5
description: Duplicate __proto__ property names
info: |
    Annex B defines an early error for duplicate PropertyName of `__proto__`,
    in object initializers, but this does not apply to Object Assignment
    patterns
---*/

// Explicitly define an "own" property to avoid Annex B "__proto__ Property
// Names in Object Initializers" semantics (in environments which implement
// that extension)
function Test() {
    var value = Object.defineProperty({}, '__proto__', { value: 123 });
    var result, x, y;

    result = { __proto__: x, __proto__: y } = value;

    assert.sameValue(result, value);
    assert.sameValue(x, 123, 'first AssignmentProperty');
    assert.sameValue(y, 123, 'second AssignmentProperty');

    result = x = y = null;

// CoverParenthesizedExpressionAndArrowParameterList
    result = ({ __proto__: x, __proto__: y } = value);

    assert.sameValue(result, value);
    assert.sameValue(x, 123, 'first AssignmentProperty (CPEAAPL)');
    assert.sameValue(y, 123, 'second AssignmentProperty (CPEAAPL)');
}

// preheat
const NUMBER_OF_PREHEAT = 1;
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
    Test();
}

ArkTools.jitCompileAsync(Test);
assert.sameValue(ArkTools.waitJitCompileFinish(Test), true, '[JIT] JIT disabled.');

// test
const NUMBER_OF_TEST = 1; // or 2
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
    Test();
}
